﻿Imports System.IO

<Serializable()> _
Public Class Objects

    Private _ArrayOfObjectTypeTemplates As ObjectTypeTemplate()
    Public Property ArrayOfObjectTypeTemplates() As ObjectTypeTemplate()
        Get
            Dim myList As ObjectTypeTemplate() = _ArrayOfObjectTypeTemplates
            If myList Is Nothing Then
                myList = New List(Of ObjectTypeTemplate)().ToArray
                _ArrayOfObjectTypeTemplates = myList
            End If
            Return myList
        End Get
        Set(ByVal value As ObjectTypeTemplate())
            _ArrayOfObjectTypeTemplates = value
        End Set
    End Property
    Public Function DictionaryOfObjectTypeTemplates() As Dictionary(Of String, ObjectTypeTemplate)
        Dim myDic As New Dictionary(Of String, ObjectTypeTemplate)
        Dim myArray As ObjectTypeTemplate() = ArrayOfObjectTypeTemplates
        For Each myOTT As ObjectTypeTemplate In myArray
            myDic.Add(myOTT.ID.ToString, myOTT)
        Next
        Return myDic
    End Function
    Public Overloads Sub AddObjectTypeTemplate(ByVal anArrayOfObjectTypeTemplate As ObjectTypeTemplate())
        For Each myItem As ObjectTypeTemplate In anArrayOfObjectTypeTemplate
            AddObjectTypeTemplate(myItem)
        Next
    End Sub
    Public Overloads Sub AddObjectTypeTemplate(ByVal aListOfObjectTypeTemplate As List(Of ObjectTypeTemplate))
        For Each myItem As ObjectTypeTemplate In aListOfObjectTypeTemplate
            AddObjectTypeTemplate(myItem)
        Next
    End Sub
    Public Overloads Sub AddObjectTypeTemplate(ByVal anObjectTypeTemplate As ObjectTypeTemplate)
        Dim myList As New List(Of ObjectTypeTemplate)(ArrayOfObjectTypeTemplates)
        myList.Add(anObjectTypeTemplate)
        ArrayOfObjectTypeTemplates = myList.ToArray
    End Sub

    Public Overrides Function ToString() As String
        Dim mySW As New StringWriter
        With mySW
            .WriteLine(String.Format("Number of ObjectTypeTemplates:        {0}", DictionaryOfObjectTypeTemplates.Count))
            For Each myObjectTypeTemplate As ObjectTypeTemplate In DictionaryOfObjectTypeTemplates.Values
                .WriteLine(myObjectTypeTemplate.ToString(0))
            Next
        End With
        Return mySW.ToString
    End Function

End Class
